/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.io.*;
import java.awt.font.*;
import javax.swing.JFileChooser;
import java.awt.*;
import java.awt.Event;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.ImageIcon;
import java.util.ArrayList;
import java.io.*;

/**
 *
 * @author Farrar
 */
public class LoadGame2{
    private static JLabel header;
    private static JLabel header1;
    private static JLabel header2;
    private static JButton browse;
    private static JButton back;
    private static JButton blank;
    private static JButton next;
    private static ImageIcon icon;
    private static ImageIcon browseIcon;
    private static ImageIcon backIcon;
    private static ImageIcon nextIcon;
    private static JFrame frame;
    private static JPanel mainPanel;
    private static JPanel panel1;
    private static JPanel panel2;
    private static JPanel panel3;
    private static String filename;
    private static File selectedFile;
    public static void main(String args[]) {
        new LoadGame2();
    }

    public LoadGame2() {
        final int WINDOW_WIDTH = 550;
        final int WINDOW_HEIGHT = 400;
        frame = new JFrame("Group I");
        frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        frame.setLayout(new GridLayout(3, 0));
        
        panel1 = new JPanel();
        panel1.setBackground(new Color(0, 0, 70));
        header=new JLabel("Uppers ");
        header.setFont(new Font("Serif", Font.BOLD, 48));
        header.setForeground(Color.red);
        panel1.add(header);
        frame.getContentPane().add(panel1);
        frame.add(panel1);

        header1=new JLabel("And ");
        header1.setFont(new Font("Serif", Font.BOLD, 48));
        header1.setForeground(Color.white);
        panel1.add(header1);
        frame.getContentPane().add(panel1);
        frame.add(panel1);
        
        header2=new JLabel("Downers");
        header2.setFont(new Font("Serif", Font.BOLD, 48));
        header2.setForeground(Color.blue);
        panel1.add(header2);
        frame.getContentPane().add(panel1);
        frame.add(panel1);
        
        panel2 = new JPanel();
        panel2.setLayout(new GridLayout(0, 3));
        browse = new JButton("Browse...");
        
        browse.setContentAreaFilled(false);
        browse.setBorderPainted(false);
        //browse.setPreferredSize(new Dimension(10,10));
        browse.setForeground(Color.red);
        browse.setBackground(Color.white);
        browse.setFont(new Font("Serif", Font.BOLD, 36));
        browse.addActionListener(new ActionListener() {
        
            public void actionPerformed(ActionEvent ae) {
            JFileChooser fileChooser = new JFileChooser();
            int returnValue = fileChooser.showOpenDialog(null);
            if (returnValue == JFileChooser.APPROVE_OPTION) {
            selectedFile = fileChooser.getSelectedFile();
            System.out.println(selectedFile.getName());
            filename=selectedFile.getName();
            load(2);
        }
      }
    });
     
        panel2.add(browse);
        panel2.setBackground(new Color(0, 0, 70));
        frame.getContentPane().add(panel2);

        panel3 = new JPanel();
        panel3.setLayout(new GridLayout(0, 3));
        panel3.setBackground(new Color(0, 0, 70));
        frame.getContentPane().add(panel3);
        back = new JButton("Back");
        back.setFont(new Font("Serif", Font.BOLD, 36));
        back.setPreferredSize(new Dimension(30, 20));
        //back.setOpaque(false);
        back.setContentAreaFilled(false);
        back.setBorderPainted(false);
        back.setForeground(Color.blue);
        //back.addActionListener(this);
        panel3.add(back);

        blank = new JButton("");
        blank.setContentAreaFilled(false);
        blank.setBorderPainted(false);
        panel3.add(blank);


        nextIcon = new ImageIcon("C:/Users/Farrar/Desktop/SEScreen/next.png");
        next = new JButton("Next");
        next.setFont(new Font("Serif", Font.BOLD, 36));
        next.setPreferredSize(new Dimension(30, 20));
        //back.setOpaque(false);
        next.setContentAreaFilled(false);
        next.setBorderPainted(false);
        next.setForeground(Color.blue);
        //back.addActionListener(this);
        panel3.add(next);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

 
 public void load(int line) {
        ArrayList<String> saves = new ArrayList<String>();
       try {
            FileReader reader = new FileReader(selectedFile);
            BufferedReader buffer = new BufferedReader(reader);
            while (buffer.ready()) {
                String string_from_file = buffer.readLine();
                saves.add(string_from_file);
            }
            buffer.close();
        } //catch possible errors
        catch (Exception e) {
        }
        String data = saves.get(line);
        String[] s1 = data.split("[.,!?:;]+\\s*");
        System.out.println("Save successful??");
        for (int i = 0; i < s1.length; i++) {
            System.out.println(s1[i]);
        }
    }
}